package org.zongf.learn.grpc.remote.impl;

import com.learn.grpc.grpc.HelloServiceGrpc;
import com.learn.grpc.hello.PingRequest;
import com.learn.grpc.hello.PingResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zongf.learn.grpc.remote.IHelloRpcRmtService;
import org.zongf.learn.grpc.starter.anno.GrpcClient;

/**
 * @author zongf
 * @since 2023-07-10
 **/
@Service
@GrpcClient(stub = HelloServiceGrpc.HelloServiceBlockingStub.class, service = "learn-grpc-spring-server")
public class TestRpcRmtService implements IHelloRpcRmtService {

    @Autowired
    private HelloServiceGrpc.HelloServiceBlockingStub stub;

    @Override
    public String ping(String name) {
        PingRequest request = PingRequest.newBuilder()
                .setContent(name)
                .build();
        PingResponse response = stub.ping(request);

        return response.getData();
    }
}
